package str

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestLeftPad(t *testing.T) {
	got := LeftPad("12", 3, "0")
	expected := "012"

	require.Equal(t, expected, got)
}

func TestRightPad(t *testing.T) {
	got := RightPad("12", 3, "0")
	expected := "120"

	require.Equal(t, expected, got)
}

func TestLeftPadNotEfficient(t *testing.T) {
	got := leftPad("12", 3, "0")
	expected := "012"

	require.Equal(t, expected, got)
}

var leftPad1 string

func BenchmarkLeftPad(b *testing.B) {
	s := "12345678901234567890123456789012345678901234567890"
	pad := 100

	var a string

	b.ResetTimer()
	b.ReportAllocs()

	for i := 0; i < b.N; i++ {
		a = LeftPad(s, pad, "0")
	}

	leftPad1 = a
}

var leftPad2 string

func BenchmarkLeftPadV2(b *testing.B) {
	s := "12345678901234567890123456789012345678901234567890"
	pad := 100
	b.ResetTimer()
	b.ReportAllocs()

	var a string
	for i := 0; i < b.N; i++ {
		a = leftPad(s, pad, "0")
	}

	leftPad2 = a
}
